package com.exercicios.futebol.converter;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;

@FacesConverter("com.exercicios.futebol.converter.NumericValue")
public class NumericValueConverter implements Converter {

	@Override
	public Object getAsObject(FacesContext arg0, UIComponent arg1, String arg2) {

		Double valor = 0.0;

		if (!arg2.equals("")) {
			if (arg2.equalsIgnoreCase("um milhão"))
				valor = 1000000.0;
			else if (arg2.equalsIgnoreCase("cem mil"))
				valor = 100000.0;
			else if (arg2.equalsIgnoreCase("mil"))
				valor = 1000.0;
			else {
				valor = Double.parseDouble(arg2);
			}
		}

		return valor;
	}

	@Override
	public String getAsString(FacesContext arg0, UIComponent arg1, Object arg2) {
		
		return Double.toString((Double)arg2);
	}

}
